home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ANIVGA.ZIP / EXAMPLE6.PAS < prev    next >
Pascal/Delphi Source File  |  1992-08-18  |  4KB  |  112 lines

  1. PROGRAM Example6;
  2.  
  3. {Another example how to use an image as a scrolling background; this time, }
  4. {a 8x4 tile image will be used, but pasted to the same area as in the pre- }
  5. {vious example!}
  6. {Just for the case that you are bored, this example also shows how to "tie"}
  7. {output of OutTextXY() and sprites to an absolute screen position (in      }
  8. {scrolling mode, of course, because otherwise it would be trivial)}
  9.  
  10. {$X+} {to ignore results of functions}
  11. USES ANIVGA,CRT;
  12. CONST TileName1='black.COD';     {1 black tile}
  13.       TileName2='marmor.COD';    {32 tiles, captured from Win3.1}
  14.       tiles_per_row=8;           {These are the proportions of }
  15.       tiles_per_column=4;        {the above 4 tile file: 2x2!  }
  16.       SpriteName='flower.COD';
  17.       FlowerLoadNumber=1;        {load number for sprite}
  18.       Flower1=0;                 {sprite number}
  19.       Flower2=1;                 {another one  }
  20.       ch:Char=#0;
  21.  
  22. PROCEDURE Init;
  23. VAR gx,gy,count:INTEGER;
  24.     Row:WORD;
  25. BEGIN
  26.  XTiles:=0; YTiles:=0;
  27.  SetBackgroundMode(scrolling);
  28.  SetBackgroundScrollRange(50,50,300,100);
  29.  
  30.  {paste tiles into this background, using circular enumeration}
  31.  count:=0; Row:=0;
  32.  gy:=BackY1;
  33.  REPEAT
  34.   gx:=BackX1;
  35.   REPEAT
  36.    PutTile(gx,gy,succ(count + (Row MOD tiles_per_column)*tiles_per_row));
  37.    inc(count); count:=count MOD tiles_per_row;
  38.    inc(gx,16);
  39.   UNTIL gx>BackX2;
  40.   inc(Row); {or: Row:=(Row+1) MOD tiles_per_row}
  41.   inc(gy,16);
  42.  UNTIL gy>BackY2;
  43.  
  44.  {load sprite:}
  45.  IF loadSprite(SpriteName,FlowerLoadNumber)=0
  46.   THEN BEGIN
  47.         WRITELN('Couldn''t access file '+SpriteName+' : '+GetErrorMessage);
  48.         halt(1)
  49.        END;
  50. END;
  51.  
  52. BEGIN
  53.  Init;
  54.  InitGraph;
  55.  LoadTile(TileName1,0); {load the black tile as tile #0 = surrounding pattern}
  56.  IF Error<>Err_None
  57.   THEN BEGIN
  58.         CloseRoutines;
  59.         WRITELN('Couldn''t access file '+TileName1+' : '+GetErrorMessage);
  60.         halt(1)
  61.        END;
  62.  LoadTile(TileName2,1); {load the 4 tiles as tile #1..4 = inner picture}
  63.  IF Error<>Err_None
  64.   THEN BEGIN
  65.         CloseRoutines;
  66.         WRITELN('Couldn''t access file '+TileName2+' : '+GetErrorMessage);
  67.         halt(1)
  68.        END;
  69.  
  70.  SetCycleTime(0); {animation as fast as possible}
  71.  
  72.  SpriteN[Flower1]:=FlowerLoadNumber;
  73.  SpriteX[Flower1]:=0;
  74.  SpriteY[Flower1]:=0;
  75.  SpriteN[Flower2]:=FlowerLoadNumber;
  76.  SpriteX[Flower2]:=StartVirtualX+100; {tie 2nd flower to absolute position}
  77.  SpriteY[Flower2]:=StartVirtualY+100;
  78.  
  79.  Animate;
  80.  OutTextXY(StartVirtualX+10,StartVirtualY+10,1-PAGE,'This text won''t scroll!');
  81.  {show text the 1st time!}
  82.  REPEAT
  83.   IF Hitdetect(Flower1,Flower2) THEN BEGIN sound(1000); delay(5); nosound END;
  84.   if KeyPressed
  85.    THEN BEGIN
  86.          WHILE KeyPressed DO ch:=Upcase(ReadKey);
  87.          CASE ch OF
  88.           'I':dec(SpriteY[Flower1]);  {change position of sprite with I,J,K,M}
  89.           'J':dec(SpriteX[Flower1]);
  90.           'K':inc(SpriteX[Flower1]);
  91.           'M':inc(SpriteY[Flower1]);
  92.           'E':dec(StartVirtualY,10);  {change position of whole scene with}
  93.           'S':dec(StartVirtualX,10);  {E,S,D,X}
  94.           'D':inc(StartVirtualX,10);
  95.           'X':inc(StartVirtualY,10);
  96.          END;
  97.          IF POS(ch,'IJKMESDX')>0
  98.           THEN BEGIN {=only if something changed}
  99.                 SpriteX[Flower2]:=StartVirtualX+100;
  100.                 SpriteY[Flower2]:=StartVirtualY+100;
  101.                 Animate; 
  102.                 OutTextXY(StartVirtualX+10,StartVirtualY+10,1-PAGE,
  103.                           'This text won''t scroll!')
  104.                END
  105.         END;
  106.  
  107.  UNTIL (ch='Q') OR (ch=#27);  {"Q" or ESC to quit}
  108.  
  109.  CloseRoutines;
  110.  
  111. END.
  112.